/**
* Created by ren on 2016/12/23.
*/
<template>
  <div class='banner'>
    <div id="myCarousel" class="carousel slide">
      <!-- 轮播（Carousel）指标 -->
      <ol class="carousel-indicators" style="bottom: -10px;">
        <li v-for="(item,index) in bannerData" href="#myCarousel" :data-slide-to="index"
            :class="{active:index===0}"></li>
      </ol>
      <!-- 轮播（Carousel）项目 -->
      <div class="carousel-inner">
        <div v-for="(item,index) in bannerData" :class="{item:true,active:index===0}" @click="toNewShow(item)">
          <img v-lazy="loadImg(item.picurl)">
        </div>
        <!-- 轮播（Carousel）导航 -->
        <a class="carousel-control1 left" href="#myCarousel"
           data-slide="prev"><img src="../assets/banner-left.png" alt="">
        </a>
        <a class="carousel-control1 right" href="#myCarousel"
           data-slide="next"><img src="../assets/banner-right.png" alt="">
        </a>
      </div>
    </div>
</template>

<script>
  import API from '../api'
  export default {
    name: 'banner',
    data: function () {
      return {
        bannerData: []
      }
    },
    methods: {
      loadImg: function (path) {
        return API.path + path
      },
      getBanner: function () {
        this.$http.post(API.findBanners, {
          showType: 0
        }).then((ret) => {
          const result = ret.body
          if (result.code === 1) {
            this.bannerData = result.object
          } else {
            this.password = ''
            this.notifyStatus = '0|' + result.message
          }
        }, (err) => {
          this.password = ''
          console.log(err)
        })
      },
      toNewShow: function (item) {
        if (item.turnType === 2) {
          this.$cookie.set('bannerContent', item.content)
          this.$router.push({name: 'newShow'})
        } else if (item.turnType === 1) {
          window.open(item.linkurl)
        } else {
          if (item.type === 1) {
            this.$router.push({name: 'jSJDetail', params: {jsjId: item.id}})
          } else if (item.type === 2) {
            this.$router.push({name: 'goodsdetail', params: {goodsId: item.id}})
          } else if (item.type === 3) {
            this.$router.push({name: 'dingTouDetail'})
          }
        }
      }
    },
    mounted: function () {
      this.getBanner()
    }
  }
</script>
